﻿using System.Windows;

namespace SHomeWorkshop.LunarPresentation
{
    /// <summary>
    /// Interaction logic for App.xaml
    /// </summary>
    public partial class App : Application
    {
        void App_Startup(object sender, StartupEventArgs e)
        {
            // 取命令行参数。
            for (int i = 0; i != e.Args.Length; ++i)
            {
                Globals.commandLineList.Add(e.Args[i]);
            }

            Application.Current.SessionEnding += new SessionEndingCancelEventHandler(Current_SessionEnding);
        }

        /// <summary>
        /// 此事件用以在“文档被修改且未保存的情况下，直接关闭Windows时让用户有机会保存文件”。
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void Current_SessionEnding(object sender, SessionEndingCancelEventArgs e)
        {
            if (this.MainWindow != null)
            {
                MainWindow win = this.MainWindow as MainWindow;
                if (win != null)
                {
                    if (win.CloseDocuments() == false) e.Cancel = true;
                    else { e.Cancel = false; }
                }
            }
        }
    }
}
